let vm=new Vue({
  el:'#app',
  data(){
    return{
      user:{
        username:'',
        password:''
      },
      errorUsername:false,
      errorUsernameMsg:'请输入正确的用户名或手机号',
      errorPassword:false,
      errorPasswordMsg:'密码最少8位，最长20位',
      remembered:false,
    }
  },
  mounted(){},
  methods:{
    checkUsername(){
      console.log("检查用户名")
      let reg = /^[a-zA-Z0-9_-]{3,20}$/
      if(reg.test(this.user.username)){
        this.errorUsername=false

      }else{
        this.errorUsername=true
        this.errorUsernameMsg='请输入正确的用户名或手机号'
      }
      return this.errorUsername
    },
    checkPassword(){
      console.log("检查密码")
      let reg=/^[0-9a-zA-Z]{6,20}$/
      if(reg.test(this.user.password)){
        this.errorPassword=false
      }else{
        this.errorPassword=true
        this.errorPasswordMsg='密码最少6位，最长20位'
      }

      return this.errorPassword
    },
    toLogin(){
      if(this.checkUsername() || this.checkPassword()){
        window.event.returnValue=false
        return
      }

      console.log("开始登录")
    },
    toLoginQQ(){
      let next=get_query_string('next')||'/'
      console.log("返回的next路径：",next)
      let url='/qq/login?next='+next
      console.log("url="+url)
      axios.get(url, {responseType:'json'})
        .then(response=>{
          console.log("success：",response)
          //这里的loginUrl就是 第一步的获取 Authorization Code https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=xxx&redirect_uri=xxx&state=xxx
          //跳转QQ登录页面
          if(response.data.code==0){
            location.href=response.data.loginUrl
          }

        })
        .catch(error=>{
          console.log("error: ",error.response)
        })
    },
    toLoginWX(){},
    toRegister(){},
    toIndex(){},
  },
})